package logic

import (
	"context"
	"errors"
	"video-management-system/model"

	"video-management-system/userrpc/internal/svc"
	"video-management-system/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentDelLogic {
	return &CommentDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 删除评论
func (l *CommentDelLogic) CommentDel(in *userrpc.CommentDelRequest) (*userrpc.CommentDelResponse, error) {
	// todo: add your logic here and delete this line
	var findComment model.CommentInfo
	err := findComment.FindCommentById(model.DB, in)
	if err != nil {
		return nil, err
	}
	if findComment.ID == 0 {
		return nil, errors.New("评论不存在")
	}
	var comment model.CommentInfo
	err = comment.CommentDel(model.DB, in)
	if err != nil {
		return nil, errors.New("删除失败")
	}
	return &userrpc.CommentDelResponse{}, nil
}
